# 获取鼠标所在坐标和颜色

import time
import pyautogui

PC_COM = 0  # 0-家庭 1-公司

if __name__ == "__main__":
    dpi_x = pyautogui.size()[0]  # 长 默认2240
    dpi_y = pyautogui.size()[1]  # 高 默认1400

    x_radio = dpi_x / 2240  # 自动进行坐标换算
    y_radio = dpi_y / 1400

    print("\r\nx和y方向的像素点：", dpi_x, dpi_y)
    print("\r\nx和y方向的像素点和2240 1400的比例：", x_radio, y_radio)
    while 1:
        try:
            time.sleep(1)

            x, y = pyautogui.position()
            rgb = pyautogui.screenshot().getpixel((x, y))
            posi = 'x:' + str(x).rjust(4) + ' y:' + str(y).rjust(4) + '  RGB:' + str(rgb)
            if PC_COM == 1:
                print('\r', posi)

            x = x / x_radio
            y = y / y_radio
            posi = 'x:' + str(int(x)).rjust(4) + ' y:' + str(int(y)).rjust(4) + '  RGB:' + str(rgb)
            if PC_COM == 0:
                print('\r', posi)
        except:
            print("error")

